import { Language } from "../../../extend/language/Language";
import { TRuneManual } from "../../../Message/Db/Tables/TRuneManual";
import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { SkillConfig } from "./SkillConfig";
type int = number;
//class RuneManualConfig
    
    export  class RuneManualConfig
    {
        constructor()
        {
            
            this.categoryTypes = [RuneManualConfig.Type_Normal, RuneManualConfig.Type_WuSheng, RuneManualConfig.Type_YiShen, RuneManualConfig.Type_FaHuang, RuneManualConfig.Type_TianZun];
            this.categoryNames = [Language.getString(80100), Language.getString(80101), Language.getString(80102), Language.getString(80103), Language.getString(80104)];
            this.categoryOneSubNames = [RuneManualConfig.Name_All, RuneManualConfig.Name_ChangSheng, RuneManualConfig.Name_HuaJie];
            this.categoryCareerSubNamesPre = [RuneManualConfig.Name_All, RuneManualConfig.Name_Holy];
            this._gotList = new Map<any, any> /* flash.utils.Dictionary */();
            this._skillName_SkillId = new Map<any, any> /* flash.utils.Dictionary */();
            this.initConfig();
            return;
        }

        public filterByMinorType(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc3=null;
            var loc1=[];
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if ((loc3 = arg1[loc2] as TRuneManual) != null) 
                {
                    if (loc3.type == arg2) 
                    {
                        loc1.push(loc3);
                    }
                }
                ++loc2;
            }
            return loc1;
        }

        public getAllSkillIds(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc3=null;
            var loc1=[];
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if ((loc3 = arg1[loc2] as TRuneManual) != null) 
                {
                    if (loc3.career == arg2) 
                    {
                        if (!(loc1.indexOf(loc3.type) >= 0)) 
                        {
                            loc1.push(loc3.type);
                        }
                    }
                }
                ++loc2;
            }
            loc1.sort(this.aSort);
            return loc1;
        }

        public isHolyRune(arg1: TRuneManual): Boolean
        {
            if (arg1.typeEx == RuneManualConfig.SubType_Holy) 
            {
                return true;
            }
            return false;
        }

        /* internal  */aSort(arg1: int, arg2: int): int
        {
            if (arg1 <= arg2) 
            {
                return -1;
            }
            return 1;
        }

        /* internal  */getTypeKey(arg1: int): string
        {
            return "type_" + arg1.toString();
        }

        /* internal  */initConfig(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            this._data = new Map<any, any> /* flash.utils.Dictionary */();
            var loc1=ConfigManager.instance.getJSONByFileName("t_rune_manual.json");
            var loc5=0;
            var loc6=loc1;
            for(loc2 of loc6) 
            {
                loc3 = new TRuneManual();
                this.copyValue(loc3, loc2);
                loc4 = loc3.id.toString();
                this._data[loc4] = loc3;
            }
            return;
        }

        /* internal  */copyValue(arg1: Object, arg2: Object): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg2;
            for (loc1 in loc3) 
            {
                arg1[loc1] = arg2[loc1];
            }
            return;
        }

        public static get instance(): RuneManualConfig
        {
            if (RuneManualConfig._instance == null) 
            {
                RuneManualConfig._instance = new RuneManualConfig();
            }
            return RuneManualConfig._instance;
        }

        public getRunesByType(arg1: int): Array<any>
        {
            var loc3=null;
            var loc1=this.getTypeKey(arg1);
            if (this._gotList[loc1] != null) 
            {
                return this._gotList[loc1] as Array<any>;
            }
            var loc2=[];
            var loc4=0;
            var loc5=this._data;
            for(loc3 of loc5) 
            {
                if (loc3.career != arg1) 
                {
                    continue;
                }
                loc2.push(loc3);
            }
            this._gotList[loc1] = loc2;
            return loc2;
        }

        public filterByName(arg1: Array<any>, arg2: string): Array<any>
        {
            var loc1=0;
            if (arg2 == RuneManualConfig.Name_All) 
            {
                return arg1;
            }
            if (arg2 == RuneManualConfig.Name_Holy) 
            {
                return this.filterByExType(arg1, RuneManualConfig.SubType_Holy);
            }
            if (arg2 == RuneManualConfig.Name_ChangSheng) 
            {
                return this.filterByMinorType(arg1, RuneManualConfig.MinorType_ChangSheng);
            }
            if (arg2 == RuneManualConfig.Name_HuaJie) 
            {
                return this.filterByMinorType(arg1, RuneManualConfig.MinorType_HuaJie);
            }
            loc1 = this._skillName_SkillId[arg2];
            return this.filterByMinorType(arg1, loc1);
        }

        public getSubNamesByType(arg1: int): Array<any>
        {
            var loc5=null;
            if (arg1 == RuneManualConfig.Type_Normal) 
            {
                return this.categoryOneSubNames.concat([]);
            }
            var loc1=this.categoryCareerSubNamesPre.concat([]);
            var loc2=this.getRunesByType(arg1);
            var loc3=this.getAllSkillIds(loc2, arg1);
            var loc4=0;
            while (loc4 < loc3.length) 
            {
                if ((loc5 = SkillConfig.instance.getInfoByName(int(loc3[loc4]))) != null) 
                {
                    this._skillName_SkillId[loc5.skillName] = loc5.skillId;
                    loc1.push(loc5.skillName);
                }
                ++loc4;
            }
            return loc1;
        }

        public filterByExType(arg1: Array<any>, arg2: int): Array<any>
        {
            var loc3=null;
            var loc1=[];
            var loc2=0;
            while (loc2 < arg1.length) 
            {
                if ((loc3 = arg1[loc2] as TRuneManual) != null) 
                {
                    if (loc3.typeEx == arg2) 
                    {
                        loc1.push(loc3);
                    }
                }
                ++loc2;
            }
            return loc1;
        }

        public static /* const */Type_Normal: int=0;

        public static /* const */Type_WuSheng: int=16;

        public static /* const */Type_YiShen: int=32;

        public static /* const */Type_FaHuang: int=64;

        public static /* const */Type_TianZun: int=128;

        public static /* const */SubType_Holy: int=2;

        public static /* const */SubType_Normal: int=1;

        public static /* const */MinorType_ChangSheng: int=1;

        public static /* const */MinorType_HuaJie: int=2;

        public static /* const */Name_All: string=Language.getString(80105);

        public static /* const */Name_Holy: string=Language.getString(80106);

        public static /* const */Name_ChangSheng: string=Language.getString(80107);

        public static /* const */Name_HuaJie: string=Language.getString(80108);

        /* internal */ /* var */_data: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_skillName_SkillId: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_gotList: Map<any, any> /* flash.utils.Dictionary */;

        public /* var */categoryTypes: Array<any>;

        public /* var */categoryNames: Array<any>;

        /* internal */ /* var */categoryOneSubNames: Array<any>;

        /* internal */ /* var */categoryCareerSubNamesPre: Array<any>;

        /* internal */ /* var */_types: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: RuneManualConfig;
    }
